<script lang="ts" setup>
import { GameItem } from '@/typings';
import { computed, ref } from 'vue';

const props = defineProps<{ data: GameItem }>();
const emits = defineEmits<{ (e: 'close') }>();

const introMd = ref();

const minimum = computed(() => {
  const { system, cpu, ram, gpu, rom } = props.data.minimum;
  return {
    system: system.join(' / '),
    cpu: cpu.join(' / '),
    ram: ram.join(' / '),
    gpu: gpu.join(' / '),
    rom: rom.join(' / '),
  };
});

const recommend = computed(() => {
  const { system, cpu, ram, gpu, rom } = props.data.recommend;
  return {
    system: system.join(' / '),
    cpu: cpu.join(' / '),
    ram: ram.join(' / '),
    gpu: gpu.join(' / '),
    rom: rom.join(' / '),
  };
});

const open = () => {
  introMd.value.render(props.data.intro);
};

const close = () => emits('close');
</script>

<template>
  <el-dialog
    class="game-dialog"
    :model-value="true"
    :title="data.name"
    @opened="open"
    @closed="close"
    fullscreen
  >
    <el-scrollbar height="calc(100vh - 54px)">
      <div class="container">
        <el-image class="game-cover" :src="data.cover" fit="cover" lazy />
        <el-descriptions :column="3" direction="vertical">
          <el-descriptions-item label="类型">{{ data.type }}</el-descriptions-item>
          <el-descriptions-item label="版本">{{ data.version }}</el-descriptions-item>
          <el-descriptions-item label="更新">{{ data.updateTime }}</el-descriptions-item>
          <el-descriptions-item label="标签" :span="3">
            <div class="tags-wrap">
              <el-tag v-for="tag of data.tags" :key="tag">{{ tag }}</el-tag>
            </div>
          </el-descriptions-item>
          <el-descriptions-item label="简介" :span="3"></el-descriptions-item>
        </el-descriptions>
        <a-md ref="introMd" />
        <el-descriptions class="config-info" title="最低配置" :column="1" size="small" border>
          <el-descriptions-item label="系统">{{ minimum.system }}</el-descriptions-item>
          <el-descriptions-item label="CPU">{{ minimum.cpu }}</el-descriptions-item>
          <el-descriptions-item label="内存">{{ minimum.ram }}</el-descriptions-item>
          <el-descriptions-item label="显卡">{{ minimum.gpu }}</el-descriptions-item>
          <el-descriptions-item label="硬盘">{{ minimum.rom }}</el-descriptions-item>
        </el-descriptions>
        <el-descriptions class="config-info" title="推荐配置" :column="1" size="small" border>
          <el-descriptions-item label="系统">{{ recommend.system }}</el-descriptions-item>
          <el-descriptions-item label="CPU">{{ recommend.cpu }}</el-descriptions-item>
          <el-descriptions-item label="内存">{{ recommend.ram }}</el-descriptions-item>
          <el-descriptions-item label="显卡">{{ recommend.gpu }}</el-descriptions-item>
          <el-descriptions-item label="硬盘">{{ recommend.rom }}</el-descriptions-item>
        </el-descriptions>
      </div>
    </el-scrollbar>
  </el-dialog>
</template>

<style lang="scss" scoped>
:global(.game-dialog .el-dialog__header) {
  position: relative;
  margin-right: 0;
  box-shadow: var(--el-box-shadow-light);
  z-index: 1;
}
:global(.game-dialog .el-dialog__headerbtn) {
  top: 2px;
  font-size: 20px;
}
:global(.game-dialog .el-dialog__body) {
  padding: 0;
}
.game-cover {
  width: 100%;
  margin-bottom: 20px;
}
.tags-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  margin: -5px;
  .el-tag {
    margin: 5px;
    min-width: 68px;
  }
}
.config-info {
  margin-top: 12px;
  :deep(.el-descriptions__label) {
    width: 52px;
    text-align: right;
  }
}
</style>
